package search.pojo.dao.impl;

import java.io.UnsupportedEncodingException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.naming.spi.DirStateFactory.Result;

import search.pojo.Areas;
import search.pojo.dao.AreasDao;
import search.util.DBUtil;

public class AreasDaoImpl implements AreasDao{

	@Override
	public List<Areas> find(String inputArea) {
		String sql = "select * from areas where area like " + "'" + inputArea + "%" + "'";;
		PreparedStatement pst = null;
		ResultSet rSet = null;
		List<Areas> list=new ArrayList<Areas>();
		try {
			pst = DBUtil.createConnection().prepareStatement(sql);
			rSet = pst.executeQuery();
			while(rSet.next())
			{
				Areas temp = new Areas();
				temp.setId(rSet.getString("id"));
				temp.setAreaid(rSet.getString("areaid"));
				temp.setArea(new String(rSet.getString("area").getBytes(),"UTF-8"));
				temp.setCityid(rSet.getString("cityid"));
				list.add(temp);
			}
		} catch (SQLException | UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return list;
	}

}
